package com.mate.cloud.redisson.datatype;

import org.redisson.api.RFuture;
import org.redisson.api.RSet;
import org.redisson.api.RedissonClient;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutionException;

public class SetTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        RedissonClient redissonClient = RedissonClientUtil.getClient();
//        RSet<String> huihui = redissonClient.getSet("灰灰");
//        //huihui关注的人
//        List<String> huihuiMembers= Arrays.asList("james","mic","tom","颖子","梦情");
//        huihui.addAll(huihuiMembers);
//
//        RSet<String> james = redissonClient.getSet("james");
//        //james关注的人
//        List<String> jamesMembers= Arrays.asList("颖子","mic","tom","云帆","梦情","荣荣",
//                "依依","丸子","橙子","君君","蜀婷","书韵");
//        james.addAll(jamesMembers);
//        //共同关注的人
//        RFuture<Set<String>> interSet = huihui.readIntersectionAsync("james");
//        System.out.println("共同关注的人："+interSet.get());
//
//        //灰灰可能认识的人
//        RFuture<Set<String>> difSet = james.readDiffAsync("灰灰");
//        System.out.println("灰灰可能认识的人："+difSet.get());
//
        RSet<String> gupao = redissonClient.getSet("gupao");
        List<String> members= Arrays.asList("灰灰","james","mic","tom","颖子","梦情","田田","云帆","文文","荣荣",
                "依依","丸子","橙子","君君","蜀婷","书韵");
        gupao.addAll(members);
        //随机抽取三等奖3个
        RFuture<Set<String>> setRFutureThree = gupao.removeRandomAsync(3);
        //随机抽取二等奖2个
        RFuture<Set<String>> setRFutureSecond = gupao.removeRandomAsync(2);
        //随机抽取一等奖1个
        RFuture<Set<String>> setRFutureOne = gupao.removeRandomAsync(1);
        System.out.println("三等奖："+setRFutureThree.get());
        System.out.println("二等奖："+setRFutureSecond.get());
        System.out.println("一等奖："+setRFutureOne.get());
    }
}
